package com.cachopoid.utils;

import java.util.ArrayList;
import java.util.Iterator;

import com.cachopoid.R;
import com.cachopoid.vo.FotoVO;

import android.widget.BaseAdapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.content.res.TypedArray;
import android.widget.Gallery;

public class ImageAdapter extends BaseAdapter {

	int mGalleryItemBackground;
	private Context mContext;   
    ArrayList<String>listaNombreFotos = new ArrayList<String>();
    
    //TODO cargar las imagenes
   /* private Integer[] mImageIds = {
    		R.drawable.imagen_aniadir,
    		R.drawable.casapedro,
    		R.drawable.lamanduca,
    		R.drawable.mesonviana
    };*/
    
    public ImageAdapter(Context c, ArrayList<FotoVO> listaFotos) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.gallery);
        mGalleryItemBackground = attr.getResourceId(
                R.styleable.gallery_android_galleryItemBackground, 0);
        attr.recycle();
       // listaNombreFotos.add("imagen_aniadir");
        for (Iterator iterator = listaFotos.iterator(); iterator.hasNext();) {
			FotoVO fotoVO = (FotoVO) iterator.next();
			listaNombreFotos.add(fotoVO.getFoto());
			
		}
       // listaNombreFotos=listaFotos;
    }

    public int getCount() {
        //return mImageIds.length;
    	return listaNombreFotos.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(Utils.getDrawable(parent.getContext(),listaNombreFotos.get(position)));

       // imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(110, 100));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }

}
